//
//  AWIconAnnotationView.m
//  Easy Custom Map Icons
//
//  Created by Alek Åström on 2011-08-12.
//  Copyright 2011 Apps & Wonders. No rights reserved.
//

#import "AWIconAnnotationView.h"
#import "Park.h"

@implementation AWIconAnnotationView

- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    
    if (self) {
                
        // Compensate frame a bit so everything's aligned
        [self setCenterOffset:CGPointMake(-9, -3)];
        [self setCalloutOffset:CGPointMake(-2, 3)];
        
        // Add the pin icon
        iconView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 0, 32, 37)];
        [self addSubview:iconView];
    }
    
    return self;
}

- (void)setAnnotation:(id<MKAnnotation>)annotation {
    [super setAnnotation:annotation];
    
    if ([annotation isKindOfClass:[Park class]]) {
        Park *park = (Park *)annotation;
        icon = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", park.iconName]];
        [iconView setImage:icon];
    }
}

/** Override to make sure shadow image is always set
 */
- (void)setImage:(UIImage *)image {
    [super setImage:[UIImage imageNamed:@"pin_shadow.png"]];
}



@end
